
//
//  LearnHomeHeaderView.m
//  GuShiNews
//
//  Created by 丁一 on 2019/8/22.
//  Copyright © 2019 Jones. All rights reserved.
//

#import "LearnHomeHeaderView.h"
#import "NewsModel.h"
#import "XLPhotoBrowser.h"
#import "XueXiModel.h"

@interface LearnHomeHeaderView ()

@property (nonatomic, strong) UILabel *Tittle;
@property (nonatomic, strong) UILabel *bottom;
@property (nonatomic, strong) UIImageView *News_image;
@property (nonatomic, strong) UIButton    *News_button;

@end

@interface LearnHomeHeaderView ()


@end

@implementation LearnHomeHeaderView

/* 在构造方法中，创建UI*/
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        
        _Tittle = [[UILabel alloc] initWithFrame:CGRectMake(25, 15, RECRWITCH-50, 80)];
        _Tittle.font      = [UIFont boldSystemFontOfSize:23];
        _Tittle.textColor = NewsTitleColor;
        _Tittle.numberOfLines = 0 ;
        _Tittle.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_Tittle];
        
        _bottom = [[UILabel alloc] initWithFrame:CGRectMake(25, 15, RECRWITCH-50, 80)];
        _bottom.font      = [UIFont systemFontOfSize:14];
        _bottom.textColor = NewsotherColor;
        _bottom.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_bottom];
        
        _News_image                     = [[UIImageView alloc] init];
        _News_image.layer.masksToBounds = YES;
        _News_image.layer.cornerRadius  = 5;
        _News_image.contentMode         = UIViewContentModeScaleAspectFill;
        _News_image.backgroundColor = backColor;
        [self addSubview:_News_image];
        
        _News_button = [[UIButton alloc] init];
        [_News_button addTarget:self action:@selector(showimage:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_News_button];
    }
    return self;
}

- (void)showimage:(UIButton *)sender{
    
    XLPhotoBrowser *browser = [XLPhotoBrowser showPhotoBrowserWithImages:@[_Model.x_logo] currentImageIndex:0];
    browser.seletBlock = ^(BOOL tui_ok) {
        
    };
}

- (void)setModel:(XueXiModel *)Model{
    if (_Model != Model) {
        _Model = Model;
    }
//
//    NSDictionary *dic = @{NSKernAttributeName:@0.f};
//    NSMutableAttributedString * attributedString =     [[NSMutableAttributedString alloc] initWithString:_Model.x_tittle attributes:dic];
//
//    NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc]     init];
//    [paragraphStyle setLineSpacing:4];
//
//    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [_Model.x_tittle length])];
//    [_Tittle setAttributedText:attributedString];
//    [_Tittle sizeToFit];
    
    _Tittle . text = _Model.x_tittle;
    _Tittle.frame= CGRectMake(25, 15, RECRWITCH-50, _Model.title_height);

    _bottom.frame = CGRectMake(25, 15 + _Model.title_height, RECRWITCH-50, 20);
    
    _bottom.text = [NSString stringWithFormat:@"%@  %@",[JonesClass timeZhuan:_Model.x_date],_Model.x_time];
    
    _News_image.frame=CGRectMake(25, _Model.title_height+10+25, RECRWITCH-50, (RECRWITCH-50)/3*2);
    _News_button.frame=_News_image.frame;
    
    if (_Model.x_logo.length<10) {
        _News_image.hidden=YES;
        _News_button.hidden = YES;
    }else {
        _News_image.hidden=NO;
        _News_button.hidden = NO;
        [_News_image sd_setImageWithURL:[NSURL URLWithString:_Model.x_logo]];
    }
}


@end
